package org.hxzon.workeasy.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.Email;

@Entity
public class EasyUzer extends org.hxzon.project.model.Uzer {
    public static final int Power_Admin = 0;
    public static final int Power_Admins = 1;
    public static final int Power_Normal = 2;
    public static final int Power_Guest = 9;

    public static final int Department_None = 0;
    public static final int Department_Financial = 1;
    public static final int Department_Buyer = 2;
    public static final int Department_Production = 3;
    public static final int Department_Hardware = 4;
    public static final int Department_Software = 5;
    public static final int Department_ContractAuditor = 6;

    private static final long serialVersionUID = 7570429986649512051L;

    @Column(columnDefinition = DefineVarchar2048)
    @Size(max = DefineSize2048)
    private String uzerRoles;

    @Column(length = 2)
    private int adminGrade = Power_Guest;

    @Column(length = 2)
    private int department = Department_None;//部门

    @Column(columnDefinition = DefineVarchar2048)
    @Size(max = DefineSize2048)
    // @NotBlank
    @Email
    private String companyEmail;//公司邮箱

    @Column(columnDefinition = DefineVarchar2048)
    @Size(max = DefineSize2048)
    // @NotBlank
    @Email
    private String usualEmail;//常用邮箱

    @Column(columnDefinition = DefineVarchar32)
    @Size(max = DefineSize32)
    // @NotBlank
    private String companyPhone;//公司电话

    @Column(columnDefinition = DefineVarchar32)
    @Size(max = DefineSize32)
    private String mobilePhone;//移动电话

    @Column(columnDefinition = DefineVarchar2048)
    @Size(max = DefineSize2048)
    private String homeAddress;//住址

    @Column(columnDefinition = DefineVarchar2048)
    @Size(max = DefineSize2048)
    private String qqAndMsn;

    @Column(columnDefinition = "varchar(218) default ''")
    @Size(max = 32)
    private String homepage;

    @Column(columnDefinition = DefineVarchar2048)
    @Size(max = DefineSize2048)
    @Email
    private String introduction;//简介

    public String toString() {
        return this.getRealname() + "(" + this.getUsername() + "," + this.adminGrade + ")";
    }

    public boolean hasRole(String rolename) {
        return this.getUzerRoles().contains(";" + rolename + ";");
    }

    public String getUzerRoles() {
        return uzerRoles;
    }

    public void setUzerRoles(String uzerRoles) {
        this.uzerRoles = uzerRoles;
    }

    public int getAdminGrade() {
        return adminGrade;
    }

    public void setAdminGrade(int adminGrade) {
        this.adminGrade = adminGrade;
    }

    public int getDepartment() {
        return department;
    }

    public void setDepartment(int department) {
        this.department = department;
    }

    public String getCompanyEmail() {
        return companyEmail;
    }

    public void setCompanyEmail(String companyEmail) {
        this.companyEmail = companyEmail;
    }

    public String getUsualEmail() {
        return usualEmail;
    }

    public void setUsualEmail(String usualEmail) {
        this.usualEmail = usualEmail;
    }

    public String getCompanyPhone() {
        return companyPhone;
    }

    public void setCompanyPhone(String companyPhone) {
        this.companyPhone = companyPhone;
    }

    public String getMobilePhone() {
        return mobilePhone;
    }

    public void setMobilePhone(String mobilePhone) {
        this.mobilePhone = mobilePhone;
    }

    public String getHomeAddress() {
        return homeAddress;
    }

    public void setHomeAddress(String homeAddress) {
        this.homeAddress = homeAddress;
    }

    public String getQqAndMsn() {
        return qqAndMsn;
    }

    public void setQqAndMsn(String qqAndMsn) {
        this.qqAndMsn = qqAndMsn;
    }

    public String getHomepage() {
        return homepage;
    }

    public void setHomepage(String homepage) {
        this.homepage = homepage;
    }

    public String getIntroduction() {
        return introduction;
    }

    public void setIntroduction(String introduction) {
        this.introduction = introduction;
    }
}
